capture log close
clear all
set maxvar 10000
set more off
pause off
# delimit;

/* 
Figure B8
*/

local data "" ;
local output "" ;

local type_list "genr nogn prtf prbg vcps vrob vnrb shinc" ;

local genr_label	" income-generating" ;
local nogn_label 	" NON-income-generating" ;
local vcps_label	" prostitution" ;
local prbg_label	" burglary" ;
local prtf_label	" theft" ;
local vrob_label	" robbery" ;
local vnrb_label 	" non-robbery violent" ;

foreach type in 
			`type_list'
			{ ;
			local title_`type' "Any``type'_label' charge" ;
			local title_`type't "Number of``type'_label' charges" ;
			} ;

local title_shinc 	"Days in incarceration" ;

foreach sample in all { ;
	use "prwora_bw264_crime_poly1allcov_iv_`sample'.dta", clear ;
	keep if 
		(	substr(variables,1,3) == "n_1" |
			substr(variables,1,3) == "n_2" |
			substr(variables,1,3) == "n_3" |
			substr(variables,1,3) == "n_4" )
		& sample == "age18unfav" ;

	gen var = "" ;
	gen period = . ;
	foreach type in `type_list' { ;
		forval period = 1(1)4 { ;
			replace var = "`type'" 					if variables == "n_`period'crime2`type'_1997_2017" ;
			replace period = `period' 				if variables == "n_`period'crime2`type'_1997_2017" ;
			replace variables = "`type'`period'"   	if variables == "n_`period'crime2`type'_1997_2017" ;
		} ;
	} ;

	rename n_age18unfav b_endo ;
	rename sen_age18unfav se_endo ;
	keep var period b_endo se_endo ;

	gen lo95 = b_endo - 1.96*se_endo ;
	gen hi95 = b_endo + 1.96*se_endo ;

	
	foreach type in `type_list' { ;
		twoway 
			(connected b_endo 		period if var == "`type'", color(blue) )
			(rcap      hi95 lo95 	period if var == "`type'", color(blue*.5) )
			, 
			legend(off)
			title("`title_`type''`t`sample''", size(medsmall))
			xsc(r(.8 4.2)) xlab(1 "1997-01" 2 "2002-06" 3 "2007-12" 4 "2013-17") xtitle("") 
						 ytitle("IV estimate", size(medsmall))
			graphregion(color(white))
			bgcolor(white)
			ylabel(,nogrid angle(0))
			yline(0,lcolor(gray))
			;
			graph export "`output'/figB8_`type'.png", width(1000) height(750) replace ;
	} ;
	
	
} ;


